package edu.tongji.engine;

import java.util.ArrayList;
import java.util.List;

import edu.tongji.engine.common.Log;
import edu.tongji.engine.exe.ProcessInstance;

public class EngineContext{

	private static EngineContext context;
	private List<ProcessInstance> processInstances ;

	private EngineContext(){
		processInstances = new ArrayList();
	}

	public static EngineContext getEngineContextInstance(){
		if ( context == null ){
			context = new EngineContext();
		}
		return context;
	}

	public ProcessInstance createProcessInstance(String processName){
		try{
			//create an instance from db accroding processname
			ProcessInstance instance = new ProcessInstance();
			this.addProcessInstance(instance);
			return instance;
		}
		catch(Exception e ){
			System.out.println("create process instance failled! ");
			System.out.println( e.toString() );
			Log.getLoger().loger.error("create process instance failled! ", e);
			return null;
		}
	}

	public boolean addProcessInstance(ProcessInstance instance){
		if ( instance != null ){
			processInstances.add(instance);
			return true;
		}
		else{
			return false;
		}
	}

	public ProcessInstance getProcessInstance(String processName ){

		return null;
	}
}